<?php
class Model_support extends Model {
	function Model_support() {
		parent::Model();
		$this->fromSession = $this->usersession->currentUser();
	}

	/**
	 * Functie care aduce datele in grid
	 */
	function getData($aPost) {

		$iStart = $aPost["start"];
		$iLimit = $aPost["limit"];
		$sDir = $aPost["dir"];
		$sSort = $aPost["sort"];

		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("support");

		$totalCount = $this->db->count_all_results("support");
		$aData = $query->result_array();

		$data = array(
			'totalCount' => $totalCount,
			'data' => $aData
		);
		return $data;
	}

	function operation($aData) {

		$aTemp = array(
			"support_text" => $aData["support_text"],
			"support_status" => $aData["support_status"],
			"support_type" => $aData["support_type"],
			"support_pret" => $aData["support_pret"],
			"support_prioritate" => $aData["support_prioritate"]
		);

		//insert
		if ($aData["support_id"] == 0) {
			$aTemp["user_id"] = $this->fromSession["user_id"];
			$aTemp["username"] = $this->fromSession["username"];
			$this->db->insert("support", $aTemp);
		} else {
			$this->db->where("support_id", $aData["support_id"]);
			$this->db->update("support", $aTemp);
		}
	}

	/**
	 * Functie care aduce datele despre o inregistrare
	 */
	function getRecord($aData) {
		$aResult = array();
		$this->db->where("support_id", $aData["iRec"]);
		$aResult = $this->db->get("support")->row_array();
		return $aResult;
	}

}
